<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">


    <style>
        .layui-form-item .layui-input-inline {
            width: 200px;
        }
        #userForm table tr {
            width: 100%;
            margin: 0 auto;
            display: flex;
            flex-wrap: nowrap;
            justify-content: center;
        }

        #userForm table tr td{
            display: flex;
            flex-wrap: nowrap;
            margin: 10px;
        }

        #userForm table tr td .layui-input{
            width: 200px;
        }

        #userForm table tr td .layui-form-label{
            width: 100px;
        }
    </style>

</head>
<body>
更新商品
<form class="layui-form" id="userForm">
<table>
    <div class="app">

        <tr>
            <td><label class="layui-form-label">商品编码:</label>

                <input
                        required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                        id="goodsSN"
                        size="20"/></td>
        </tr>

        <tr>
            <td>
                <label class="layui-form-label"> 商品名称:</label><input
                    required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                    id="goodsName"
                    size="20"/>
            </td>
        </tr>


        <tr>
            <td>
                <label class="layui-form-label">商品规格:</label><input
                    required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                    id="goodsFormat"
                    size="20"/>
            </td>
        </tr>

    <tr>
        <td>
            <label class="layui-form-label">市场价:</label><input
                required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                id="marketPrice"
                size="20"/>
        </td>
    </tr>

    <tr>
        <td>
            <label class="layui-form-label">优惠价格:</label><input
                required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                id="realPrice"
                size="20"/>
        </td>
    </tr>

    <tr>
        <td>
            <label class="layui-form-label"> 商品说明:</label><input
                required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
                id="note"
                size="20"/>
        </td>
    </tr>

    <tr>
        <td>
                <label class="layui-form-label">商品状态:</label>
                <select id="state" lay-verify="required"  lay-filter="industry" >
                    <option value="0">请选择</option>
                    <option value="1">在售</option>
                    <option value="2">下架</option>
                </select>
        </td>
    </tr>

<tr>
    <td>
        <label class="layui-form-label">库存:</label><input
            required lay-verify="required" autocomplete="off" class="layui-input" type="text" name="reaalname"
            id="num"
            size="20"/>
    </td>
</tr>
    <tr>
        <td>
            <label class="layui-form-label"></label><input
                required lay-verify="required" autocomplete="off" class="layui-input" type="button" name="reaalname"
                id="commit" value="提交"
                size="20"/>
            <input
                    required lay-verify="required" autocomplete="off" class="layui-input" type="button" name="reaalname"
                    id="back" value="返回"
                    size="20"/>

        </td>
    </tr>

</div>
</table>
</form>
<script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/lib/getUrl.js"></script>
<script>
<!--    先查询当前ID商品的值-->
layui.use(['form', 'table', `upload`, 'layer', 'jquery', 'laydate'], function () {
    var form = layui.form;
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var laydate = layui.laydate;


    var goodsSN = request("goodsSN");
    var goodsName = request("goodsName");
    var goodsFormat = request("goodsFormat");
    var marketPrice = request("marketPrice");
    var realPrice = request("realPrice");
    var note = request("note");
    var num = request("num");
    var state = request("state");
    var lastUpdateTime = request("lastUpdateTime");

    $("#goodsSN").val(goodsSN);
    $("#goodsName").val(goodsName);
    $("#goodsFormat").val(goodsFormat);
    $("#marketPrice").val(marketPrice);
    $("#realPrice").val(realPrice);
    $("#note").val(note);
    $("#num").val(num);
    $("#state").val(state);
});

</script>

<script>

    var id = request("id");

    $("#commit").on("click",function () {
        var goodsSN = $("#goodsSN").val();
        var goodsName = $("#goodsName").val();
        var goodsFormat = $("#goodsFormat").val();
        var marketPrice = $("#marketPrice").val();
        var realPrice = $("#realPrice").val();
        var note = $("#note").val();
        var num = $("#num").val();
        var state = $("#state").val();
        console.log(state);
        if (goodsSN==""||goodsSN==null){
            alert("请输入编号");
            return false;
        }
        if (goodsName==""||goodsName==null){
            alert("请输入名称");
            return false;
        }
        if (goodsFormat==""||goodsFormat==null){
            alert("请输入规格");
            return false;
        }
        if (marketPrice==""||marketPrice==null){
            alert("请输入市场价");
            return false;
        }
        if (realPrice==""||realPrice==null){
            alert("请输入优惠价");
            return false;
        }
        if (note==""||note==null){
            alert("请输入说明");
            return false;
        }
        if (num==""||num==null){
            alert("请输入库存");
            return false;
        }
        $.ajax({
            url:"/goods/updateGoods.do",
            type:"post",
            dataType: "json",
            data:{
                "id":id,
                "state":state,
                "goodsSN":goodsSN,
                "goodsName":goodsName,
                "goodsFormat":goodsFormat,
                "marketPrice":marketPrice,
                "realPrice":realPrice,
                "note":note,
                "num":num
            },
            success:function (rec) {
                if (rec.code==0){
                    alert("更新成功")
                }else {
                    alert("更新失败")
                }
            }
        })

    });

    $("#back").on("click",function () {
        location.href="/html/shopping/goodsAdd.html"

    })


</script>
</body>
</html>